Why Create PDF from Word?
Since 1993 Adobe Systems introduced the PDF format it has rapidly become the number one universal document format on the internet. There could be without any other reasons as a growing demand for such a universal format to allow people to share their ideas and work digitally on the internet. But unfortunately it’s not easy to edit.
On the other hand, Microsoft word features many tools for editing text (alignment, paragraphs, bullets and numbering) and also it includes many languages and fonts. It also has pictures to put onto your document (clip art) and has many templates (letter, report, etc.) It should be the most suitable format to design, create and edit content.
So, if you want to create a good PDF, you can design in Word and then create PDF from Word document.
How to Use C# Create PDF from Word?
Spire.Doc, an MS Word component which enables user to perform a wide range of Word document processing tasks directly, such as generate, read, write and modify Word document for .NET and Silverlight. This library can help fast and easily create PDF from Word document.
Spire.Doc presents an easy way to convert Word to PDF. In this way, we can edit our document, after finish writing, we can get our PDF file by using SaveToFile("Sample.pdf", FileFormat.PDF) method to convert the document to PDF format.
Download Spire.Doc (or Spire.Office which includes Spire.Doc) with .NET framework 2.0 (or above) together and use the code below to create PDF from Word document.
C# Create PDF from Word
01 using System;
02 using Spire.Doc;
03 using Spire.Doc.Documents;
04
05 namespace WordToPDF
06 {
07 class Program
08 {
09 static void Main(string[] args)
10 {
11 //Create a new document
12 Document document = new Document();
13
14 //Create a section
15 Section section = document.AddSection();
16 section.PageSetup.PageSize = PageSize.A4;
17 section.PageSetup.Margins.Top = 72f;
18 section.PageSetup.Margins.Bottom = 72f;
19 section.PageSetup.Margins.Left = 89.85f;
20 section.PageSetup.Margins.Right = 89.85f;
21
22 //Add a paragraph
23 Paragraph paragraph = section.AddParagraph();
24 paragraph.Format.HorizontalAlignment = Spire.Doc.Documents.HorizontalAlignment.Left;
25
26 //Add text in the paragraph
27 String p1 = "Microsoft Word is a word processor designed by Microsoft. ";
28 String p2 = "Microsoft Office Word instead of merely Microsoft Word. ";
29 section.AddParagraph().AppendText(p1).CharacterFormat.FontSize = 14;
30 section.AddParagraph().AppendText(p2).CharacterFormat.FontSize = 14;
31
32 //Save doc file to pdf.
33 document.SaveToFile("Sample.pdf", FileFormat.PDF);
34
35 //Launching the pdf reader to open.
36 System.Diagnostics.Process.Start("Sample.pdf");
37 }
38 }
39 }
VB.Net Create PDF from Word
01 Imports System
02 Imports Spire.Doc
03 Imports Spire.Doc.Documents
04
05 Module Module1
06
07 Sub Main()
08 'Create a new document
09 Dim document As New Document()
10
11 'Create a section
12 Dim section As Section = document.AddSection()
13 section.PageSetup.PageSize = PageSize.A4
14 section.PageSetup.Margins.Top = 72.0F
15 section.PageSetup.Margins.Bottom = 72.0F
16 section.PageSetup.Margins.Left = 89.85F
17 section.PageSetup.Margins.Right = 89.85F
18
19 'Add a paragraph
20 Dim paragraph As Paragraph = section.AddParagraph()
21 paragraph.Format.HorizontalAlignment = Spire.Doc.Documents.HorizontalAlignment.Left
22
23 'Add text in the paragraph
24 Dim p1 As String = "Microsoft Word is a word processor designed by Microsoft. "
25 Dim p2 As String = "Microsoft Office Word instead of merely Microsoft Word. "
26 section.AddParagraph().AppendText(p1).CharacterFormat.FontSize = 14
27 section.AddParagraph().AppendText(p2).CharacterFormat.FontSize = 14
28
29 'Save doc file to pdf.
30 document.SaveToFile("Sample.pdf", FileFormat.PDF)
31
32 'Launching the MS Word file.
33 Process.Start("Sample.pdf")
34 End Sub
35 End Module
More about Spire.Doc
Download Spire.Doc
Purchase Spire.Doc
Since 1993 Adobe Systems introduced the PDF format it has rapidly become the number one universal document format on the internet. There could be without any other reasons as a growing demand for such a universal format to allow people to share their ideas and work digitally on the internet. But unfortunately it’s not easy to edit.
On the other hand, Microsoft word features many tools for editing text (alignment, paragraphs, bullets and numbering) and also it includes many languages and fonts. It also has pictures to put onto your document (clip art) and has many templates (letter, report, etc.) It should be the most suitable format to design, create and edit content.
So, if you want to create a good PDF, you can design in Word and then create PDF from Word document.
How to Use C# Create PDF from Word?
Spire.Doc, an MS Word component which enables user to perform a wide range of Word document processing tasks directly, such as generate, read, write and modify Word document for .NET and Silverlight. This library can help fast and easily create PDF from Word document.
Spire.Doc presents an easy way to convert Word to PDF. In this way, we can edit our document, after finish writing, we can get our PDF file by using SaveToFile("Sample.pdf", FileFormat.PDF) method to convert the document to PDF format.
Download Spire.Doc (or Spire.Office which includes Spire.Doc) with .NET framework 2.0 (or above) together and use the code below to create PDF from Word document.
C# Create PDF from Word
01 using System;
02 using Spire.Doc;
03 using Spire.Doc.Documents;
04
05 namespace WordToPDF
06 {
07 class Program
08 {
09 static void Main(string[] args)
10 {
11 //Create a new document
12 Document document = new Document();
13
14 //Create a section
15 Section section = document.AddSection();
16 section.PageSetup.PageSize = PageSize.A4;
17 section.PageSetup.Margins.Top = 72f;
18 section.PageSetup.Margins.Bottom = 72f;
19 section.PageSetup.Margins.Left = 89.85f;
20 section.PageSetup.Margins.Right = 89.85f;
21
22 //Add a paragraph
23 Paragraph paragraph = section.AddParagraph();
24 paragraph.Format.HorizontalAlignment = Spire.Doc.Documents.HorizontalAlignment.Left;
25
26 //Add text in the paragraph
27 String p1 = "Microsoft Word is a word processor designed by Microsoft. ";
28 String p2 = "Microsoft Office Word instead of merely Microsoft Word. ";
29 section.AddParagraph().AppendText(p1).CharacterFormat.FontSize = 14;
30 section.AddParagraph().AppendText(p2).CharacterFormat.FontSize = 14;
31
32 //Save doc file to pdf.
33 document.SaveToFile("Sample.pdf", FileFormat.PDF);
34
35 //Launching the pdf reader to open.
36 System.Diagnostics.Process.Start("Sample.pdf");
37 }
38 }
39 }
VB.Net Create PDF from Word
01 Imports System
02 Imports Spire.Doc
03 Imports Spire.Doc.Documents
04
05 Module Module1
06
07 Sub Main()
08 'Create a new document
09 Dim document As New Document()
10
11 'Create a section
12 Dim section As Section = document.AddSection()
13 section.PageSetup.PageSize = PageSize.A4
14 section.PageSetup.Margins.Top = 72.0F
15 section.PageSetup.Margins.Bottom = 72.0F
16 section.PageSetup.Margins.Left = 89.85F
17 section.PageSetup.Margins.Right = 89.85F
18
19 'Add a paragraph
20 Dim paragraph As Paragraph = section.AddParagraph()
21 paragraph.Format.HorizontalAlignment = Spire.Doc.Documents.HorizontalAlignment.Left
22
23 'Add text in the paragraph
24 Dim p1 As String = "Microsoft Word is a word processor designed by Microsoft. "
25 Dim p2 As String = "Microsoft Office Word instead of merely Microsoft Word. "
26 section.AddParagraph().AppendText(p1).CharacterFormat.FontSize = 14
27 section.AddParagraph().AppendText(p2).CharacterFormat.FontSize = 14
28
29 'Save doc file to pdf.
30 document.SaveToFile("Sample.pdf", FileFormat.PDF)
31
32 'Launching the MS Word file.
33 Process.Start("Sample.pdf")
34 End Sub
35 End Module
More about Spire.Doc
Download Spire.Doc
Purchase Spire.Doc